#include<bits/stdc++.h>
using namespace std;
#define reg register
#define pow2(x) (1<<(x))
#define getc() getchar_unlocked()
#define putc(c) putchar_unlocked(c)
typedef long long lli;
inline int read(){reg int x=0;reg bool f=0;reg char c=getc();while(c<'0'||c>'9'){f=(c=='-');c=getc();}while(c>='0'&&c<='9'){x=(x<<1)+(x<<3)+(c^48);c=getc();}return f?-x:x;}
inline void write(reg int x){if(x==-2147483648){putc('-'),putc('2'),putc('1'),putc('4'),putc('7'),putc('4'),putc('8'),putc('3'),putc('6'),putc('4'),putc('8');return;}if(x<0){x=-x;putc('-');}static char i32_out[15];reg int top=0;do{i32_out[++top]=(x%10)^48;x/=10;}while(x);while(top){putc(i32_out[top--]);}}
int n,a[200005],lf[200005];
int vd[1000005];
lli dp[2005][2005];
lli dfs(reg int dian,reg int r,reg int b){
    if(dian>n){
        return 0;
    }
    if(dp[r][b]!=-1){
        return dp[r][b];
    }
    return dp[r][b]=max(dfs(dian+1,dian,b)+(a[dian]==a[r]?a[r]:0),
               dfs(dian+1,r,dian)+(a[dian]==a[b]?a[b]:0));
}
int main(){
    freopen("color.in","r",stdin);
    freopen("color.out","w",stdout);
    reg int T=read();
    for(reg int _=0;_<T;++_){
        n=read();
        memset(dp,-1,sizeof(dp));
        for(reg int i=1;i<=n;i++){
            a[i]=read();
        }
        cout<<max(dfs(2,0,1),dfs(2,1,0))<<"\n";
    }
    return 0;
}
